﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.SupplierModule.ViewObject;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.SupplierModule.QueryObject
{
    public class MaterialPurchaseQO : IApplicationQueryObject
    {
        private IQueryable<MaterialPurchaseVO> GetMaterialPurchaseVOSet()
        {
            IEntityRepository<MaterialPurchase> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<MaterialPurchase>();

            IQueryable<MaterialPurchaseVO> list = from o in repository.Objects
                                                  select new MaterialPurchaseVO()
                                                  {
                                                      ID = o.ID,
                                                      Code = o.Code,
                                                      SupplierId = o.SupplierID,
                                                      OrderDate = o.OrderDate,
                                                      TotalPrice = o.TotalPrice,
                                                      OrderStateCode = o.OrderState,
                                                  };

            return list;
        }

        public MaterialPurchaseVO[] QueryMaterialPurchaseVOByPager(ISpecification<MaterialPurchaseVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<MaterialPurchaseVO> list = GetMaterialPurchaseVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<MaterialPurchaseVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}


